package org.nowcoder.leetcode.DP;

/**
 * Title  : 343. Integer Break
 * Source : https://leetcode.cn/problems/integer-break/description/
 * Author : XrazYang
 * Date   : 2023-12-26
 */

public class LeetCode_343 {
    public int integerBreak(int n) {
        //1. 定义状态: dp[i],将i拆分为整数，得到乘积最大值
        int[] dp = new int[n + 1];

        //2. 初始状态
        dp[1] = 1;
        dp[2] = 1;

        //3. 状态转移函数
        for (int i = 3; i <= n; i++) {
            for (int j = i - 1; j > 0; j--) {
                dp[i] = Math.max(dp[i], Math.max(j * dp[i - j], j * (i - j)));
            }
        }
        return dp[n];
    }
}
